<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/systemStatic/style/admin.css">
    <link rel="stylesheet" href="${ctx}/extends/zTree_v3/css/zTreeStyle/zTreeStyle.css"/>
    <link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/css/public.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body>
<iframe name="hidden_frame" id="hidden_frame" style="display: none"></iframe>
    <div style="position: relative;height: 100%;" >
        <div class="ccpui-trees">
                <p class="isShowTree colorSwitch">
                    <span style="float: left;color: #fff">&nbsp;&nbsp;组织机构管理</span>
                    <i layadmin-event="treeFlexible" class="layui-icon layui-icon-prev"></i>
                </p>
                <div style="margin-top: 6px;">
                    <ul class="ccpui-iconTree iconTrees">
                        <li><a class="iconfont iconshuaxin- zTree-refresh" title="刷新"></a></li>
                        <li><a class="iconfont iconwenjianjia1-copy zTree-triangle-d" title="展开"></a></li>
                        <li><a class="iconfont iconfolder1 zTree-triangle-r" title="收起"></a></li>
                            <input type="text"  style="width: 50%" class="orgZtreeValue">
                    </ul>
                    <ul id="treeSelectUsers" class="ztree ccpui-listZtree"></ul>
                </div>
        </div>
    <!--初表-->
        <div class="ccpui-coreContent">
            <table id="userListTable" lay-filter="userListTable"></table>
        </div>
    </div>
    <!--给用户分配组织-->
    <div hidden name="configOrgDiv" style="display: none">
        <ul class="ccpui-iconTree orgSelectBtn">
            <li><a class="iconfont iconshuaxin- zTree-refresh" title="刷新"></a></li>
            <li><a class="iconfont iconwenjianjia1-copy zTree-triangle-d" title="展开"></a></li>
            <li><a class="iconfont iconfolder1 zTree-triangle-r" title="收起"></a></li>
            <input type="text"  style="width: 128px" class="orgZtreeValues">
        </ul>
        <ul id="configOrgData" class="ztree" style="height: 450px;overflow: auto"></ul>
        <div style="text-align: center;margin-bottom: 14px">
            <button class="layui-btn saveOrg">保存</button>
            <button class="layui-btn layui-btn-danger cancelOrg">取消</button>
        </div>
    </div>
    <!-- 用户信息列表头部工具栏 -->

    <script type="text/html" id="headerToolsBar">
        <div class="ccpui-enterSel">
        <div class="layui-btn-container">
            <a class="layui-btn layui-btn-sm" lay-event="add">
                <i class="layui-icon">&#xe654;</i>
                <span>新增</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="delete">
                <i class="layui-icon">&#xe640;</i>
                <span>删除</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="query">
                <i class="layui-icon">&#xe615;</i>
                <span>查询</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="clears">
                <i class="layui-icon">&#xe9aa;</i>
                <span>重置</span>
            </a>
            <!--<a class="layui-btn layui-btn-sm" lay-event="leader">-->
                <!--<i class="layui-icon iconfont iconicon_boss"></i>-->
                <!--<span>置为领导</span>-->
            <!--</a>-->

            <a class="layui-btn layui-btn-sm" lay-event="batchupdate">
                <i class="layui-icon">&#xe9aa;</i>
                <span>批量调整</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="impuser">
                <i class="layui-icon">&#xe9aa;</i>
                <span>用户导入</span>
            </a>
            <a class="layui-btn layui-btn-sm" lay-event="expuser">
                <i class="layui-icon">&#xe9aa;</i>
                <span>用户导出</span>
            </a>

        </div>
        <form class="layui-form" action="" lay-filter="example" style="margin-top:10px;">
            <div class="table-top-filter">
                <div class="table-filter-alone">
                    <label class="layui-form-label">姓名</label>
                    <input type="text" class="layui-input filter-value" name="Q_fullName_SL" />
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">账号</label>
                    <input type="text" class="layui-input filter-value" name="Q_account_SL" />
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">状态</label>
                    <select class="filter-value" name="status">
                        <option value="">-----请选择----</option>
                        <option value="0">禁用</option>
                        <option value="1">激活</option>
                        <option value="-1">删除</option>
                    </select>
                </div>
                <!--<div class="table-filter-alone ">-->
                    <!--<label class="layui-form-label">是否领导</label>-->
                    <!--<select class="filter-value" name="isLeader">-->
                        <!--<option value="">-&#45;&#45;&#45;&#45;请选择&#45;&#45;&#45;&#45;</option>-->
                        <!--<option value="1">是</option>-->
                        <!--<option value="0">否</option>-->
                    <!--</select>-->
                <!--</div>-->
                <div class="table-filter-alone">
                    <label class="layui-form-label">主组织</label>
                    <select class="filter-value" name="isPrimary">
                        <option value="">-----请选择----</option>
                        <option value="1">是</option>
                        <option value="0">否</option>
                    </select>
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">创建时间</label>
                    <input type="text" name="Q_beginCreateTime_DL" autocomplete="off" placeholder="开始时间"
                        class="layui-input start_time filter-value">
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">——</label>
                    <input type="text" name="Q_endCreateTime_DG" autocomplete="off" placeholder="结束时间"
                           class="layui-input end_time filter-value">
                </div>
                <div class="table-filter-alone">
                    <label class="layui-form-label">是否锁定</label>
                    <select class="queryLocking filter-value" name="isLock">
                        <option value="">-----请选择----</option>
                        <option value="1">已锁定</option>
                        <option value="0">未锁定</option>
                    </select>
                </div>
                <div class="table-filter-alone ">
                    <label class="layui-form-label">是否过期</label>
                    <select class="filter-value" name="isExpired">
                        <option value="">-----请选择----</option>
                        <option value="1">已过期</option>
                        <option value="0">未过期</option>
                    </select>
                </div>
            </div>
        </form>
        </div>
    </script>
    <!-- 右侧工具栏 -->
    <!--	<a class="ccpui-btn" lay-event="detail">明细</a>-->
    <!--    <a class="ccpui-btn" lay-event="edit">编辑</a>-->
    <!--    <a class="ccpui-btn" lay-event="del">删除</a>-->
    <!--    <a class="ccpui-btn" lay-event="managementOfSub">下属管理</a>-->
    <!--    <a class="ccpui-btn" lay-event="resetPassword">重置密码</a>-->
    <!--    <a class="ccpui-btn" lay-event="setStatus">设置状态</a>-->
    <!--    <a class="ccpui-btn" lay-event="editUserOrg">调整组织</a>-->
    <!--    {{# if(d.isOnline == 0){ }}-->
    <!--    <button class="ccpui-btn ccpui-btn-disabled" lay-event="setOffline" disabled>置为离线</button>-->
    <!--    {{# }else{ }}-->
    <!--    <button class="ccpui-btn" lay-event="setOffline" >置为离线</button>-->
    <!--    {{# } }}-->
    <script type="text/html" id="userRightToolsBar">
            <a class="layui-btn layui-btn-xs" lay-event="detail">明细</a>
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            <!--{{# if(d.sortNumber == 1){ }}-->
                <!--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delLeader">取消领导</a>-->
            <!--{{# } }}-->
            <a class="layui-btn layui-btn-xs" lay-event="managementOfSub">下属管理</a>
            <a class="layui-btn layui-btn-xs" lay-event="resetPassword">重置密码</a>
            <a class="layui-btn layui-btn-xs" lay-event="setStatus">设置状态</a>
            <!--<a class="layui-btn layui-btn-xs" lay-event="editUserOrg">调整组织</a>-->
            {{# if(d.isCurrent == 0){ }}
                {{# if(d.isOnline == 0){ }}
                <button class="layui-btn layui-btn-disabled layui-btn-xs isOnline" lay-event="setOffline" disabled>置为离线</button>
                {{# }else{ }}
                <button class="layui-btn layui-btn-danger layui-btn-xs isOnline" lay-event="setOffline" >置为离线</button>
                {{# } }}
            {{# } }}
    </script>
    <!--<div id="orgRightMenu" class='ccpui-ztreeRightMenu'>
        <ul>
            <li id="importUser">导入用户</li>
            <li  id="exportUser">导出用户</li>
        </ul>
    </div>-->
    <div>
    <form class="layui-form  importUser-onfile" action="" lay-filter="importUser-onfile" hidden style="display: none">
        <div class="layui-form-item">
            <div>
                <a lay-submit lay-filter="importUser-ons" id="importUserAll" class="layui-btn btn-n">导入</a>
                <button type="reset" class="layui-btn layui-btn-primary cancelData">关闭</button>
            </div>
        </div>
        <table class="table-detail">
            <tr>
                <th style="width:30%;">选择文件:</span></th>
                <td>
                   <button type="button" class="layui-btn" id="fileone"><i class="layui-icon"></i>上传文件</button>
                    <span id="fileList">未选择任何文件</span>
                </td>
            </tr>
            <!--<tr>
                <th>用户模板:</th>
                <td>
                    <div id="filetwo"> <i class="layui-icon layui-icon-upload-circle"></i><span>下载模板1</span></div>
                </td>
            </tr>
            <tr>
                <th>用户+组织模板:</th>
                <td>
                     <div id="filethree"><i class="layui-icon layui-icon-upload-circle"></i><span>下载模板2</span></div>
                </td>
            </tr>-->
            <tr>
                <th>说明:</th>
                <td>
                   <span>导入用户默认密码：123456</span>
                </td>
            </tr>
        </table>
    </form>
    </div>
    <script src="${ctx}/layui/layui.js"></script>
    <script src="${ctx}/extends/jquery.min.js" type="text/javascript"></script>
    <script src="${ctx}/public/component.js" type="text/javascript"></script>
    <script src="${ctx}/extends/zTree_v3/js/jquery.ztree.all.min.js" type="text/javascript"></script>
    <script src="${ctx}/extends/zTree_v3/js/jquery.ztree.exhide.min.js" type="text/javascript"></script>
    <script>
        var fileName;
        layui.config({
            base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
        }).extend({
            index: 'index' //主入口模块
        }).use(['index','table', 'layer', 'form', 'laydate', 'totalFilter', 'setter','upload','commons','common'], function() {
                var table = layui.table;
                var layer = layui.layer,totalFilter = layui.totalFilter,form = layui.form,$ = layui.jquery,setter = layui.setter,upload=layui.upload,commons=layui.commons,common=layui.common;
                //选中的左侧角色树的节点ID
                var selectOrgId = "";
                //树状结构
                orgZtree();
                function orgZtree(){
                    $.ajax({
                        url: serverPath.systemPath + setter.sysLinkPath + "sysOrg/list",
                        type: "get",
                        contentType: 'application/json',
                        dataType: 'json',
                        success: function(data) {
                            var zNodes = data.data;
                            var setting = {
                                view: {
                                    showLine: false,
                                    nameIsHTML: true, //允许name支持html
                                    selectedMulti: false
                                },
                                edit: {
                                    enable: false,
                                    editNameSelectAll: false
                                },
                                data: {
                                    key: {
                                        title: "orgName"
                                    },
                                    simpleData: {
                                        enable: true,
                                        idKey:"orgId",
                                        pIdKey:"orgSupId"
                                    }
                                },
                                callback: {
                                    onClick: onClickUsers
                                }
                            };
                            $.fn.zTree.init($('#treeSelectUsers'), setting, zNodes);
                            component.fuzzySearch('treeSelectUsers','.orgZtreeValue',null,true); //初始化模糊搜索方法
                        },
                    });
                }

                function hideRMenu() {
                    if ($("#orgRightMenu")) $("#orgRightMenu").css({"visibility": "hidden"});
                    $("body").unbind("mousedown", onBodyMouseDown);
                }
                function onBodyMouseDown(event){
                    if (!(event.target.id == "orgRightMenu" || $(event.target).parents("#orgRightMenu").length>0)) {
                        $("#orgRightMenu").css({"visibility" : "hidden"});
                    }
                }


                //右键菜单导出导入功能
                // upload.render({
                //     elem: '#fileone'
                //     ,url: '/upload/'
                //     ,accept: 'file' //普通文件
                //     ,done: function(res){
                //     }
                // });
                //右键菜单导出导入功能
                upload.render({
                    elem: '#fileone'
                    ,url: '/system/sysUser/impuserExcel'
                    ,auto: false
                    ,accept: 'file' //普通文件
                    ,bindAction: '#importUserAll'
                    ,exts:'xls|xlsx'
                   ,choose: function(obj){
                        obj.preview(function(index, file, result){
                            fileName=file.name;
                            $("#fileList").text(fileName);
                        });
                    }
                    ,done: function(res){
                        var msg=res.data;
                        if(msg==""){
                            layer.alert("导入成功！", {skin: 'btn-class'}, function () {
                                layer.closeAll();
                                table.reload('userListTable', {
                                    page: {curr: 1, limit: 10}
                                });
                                totalFilter.init('userListTable');
                                commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                            });
                        }else{
                            layer.alert(msg, {icon: 2});
                        }
                    }
                });

            $('#importUserAll').click(function () {
                if(fileName == undefined) {
                    layui.layer.alert('请选择文件');
                }
            });

            function onClickUsers(event, treeId, treeNode, clickFlag) {
                    selectOrgId = treeNode.orgId;
                    common.tableConditionRender("userListTable","example",{where:{"orgId":treeNode.orgId}},true);
                    commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                }

                //展开
                $(".iconTrees .zTree-triangle-d").click(function() {
                    $.fn.zTree.getZTreeObj("treeSelectUsers").expandAll(true);
                });
                //收起
                $(".iconTrees .zTree-triangle-r").click(function() {
                    $.fn.zTree.getZTreeObj("treeSelectUsers").expandAll(false);
                });
                //刷新
                $(".iconTrees .zTree-refresh").click(function() {
                    orgZtree();
                });

                //弹窗设置
                // $('body > [name=configOrgDiv]').remove();
                // $('body').append($('[name=configOrgDiv]'));
                // $('body > form.importUser-onfile').remove();
                // $('body').append($('form.importUser-onfile'));

            var tableHeight = commons.tabHeight();
                //初表
                table.render({
                    elem: '#userListTable',
                    cellMinWidth: 80,
                    title: '用户信息列表',
                    height: tableHeight,
                    url: serverPath.systemPath + setter.sysLinkPath + 'sysUser/list', //数据接口
                    page: true, //开启分页
                    method: 'get',
                    defaultToolbar: ['filter', 'print'],
                    toolbar: '#headerToolsBar',
                    autoSort: false,//禁用前端排序
                    // even: true,//各行变色

                    cols: [
                        [
                            {type: 'checkbox'},
                            {field: 'userId', title: 'ID', sort: true, hide: true},
                            {field: 'orgId', title: 'org', sort: true, hide: true},
                            {field: 'fullName',align:'center', title: '姓名', sort: true},
                            {field: 'account',align:'center',title: '账号', sort: true},
                            //{field: 'sortNumber',width:100,align:'center',title: '领导', sort: true,templet:function (d) { if(d.sortNumber==1){ return '是'; }else{ return '否';} }},
                            {field: 'createTime',align:'center',title: '创建时间', templet: function(d) {return component.timeData(d.createTime);}, sort: true},
                            {field: 'sortNumber',width:80,align:'center', edit: 'text',title: '排序', sort: true},
                            {field: 'isExpired', width:100,align:'center',title: '过期', sort: true, templet: function(d) {if (d.isExpired == 0) {return '否';}return '是';}},
                            {
                                field: 'status', title: '状态',width:100,align:'center', sort: true, templet: function (d) {
                                    if (d.status == '0') {
                                        return '禁用';
                                    }
                                    if (d.status == '1') {
                                        return '激活';
                                    }
                                    if (d.status == '-1') {
                                        return '删除';
                                    }
                                    return '';
                                }
                            },
                            {field: 'isLock', title: '锁定',width:100,align:'center', templet: function(d) {if (d.isLock == 0) {return '未锁定';}return '已锁定';}, sort: true},
                            {field: 'fromType', width:120,align:'center',title: '数据来源', sort: true, templet: function(d) {
                                    if (d.fromType == '0') {
                                        return '系统添加';
                                    }
                                    if (d.fromType == '1') {
                                        return 'AD同步';
                                    }
                                    if (d.fromType == '2') {
                                        return 'AD同步';
                                    }
                                    return '';
                                }
                            }, {align: 'center', title: '管理', toolbar: '#userRightToolsBar'}
                        ]
                    ],
                    done:function () {
                        table.resize('userListTable');
                        common.tableSelectCon('.ccpui-enterSel .layui-form input','a[lay-event=query]','.ccpui-enterSel')
                    }
                });
                totalFilter.init('userListTable');

                //监听用户信息列表头部工具栏事件
                table.on('toolbar(userListTable)', function(obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    var data = checkStatus.data;
                    switch (obj.event) {
                        case 'add':
                            layer.open({
                                type: 2,
                                area: ['1000px', '610px'],
                                title: ['新增用户信息', 'font-size:18px;'],
                                content: serverPath.systemPath + setter.sysLinkPath + 'sysUser/view/addEdit?selectOrgId='+selectOrgId
                            });
                            break;
                        case 'delete':
                            if (data.length === 0) {
                                layer.msg('请先选择一行数据！');
                            } else {
                                var seleIds = [];
                                for (var i = 0; i < data.length; i++) {
                                    seleIds.push(data[i].userId);
                                }
                                var t_date = {};
                                t_date.userId = seleIds.join(",");
                                layer.confirm('确定删除当前数据吗？', function() {
                                    $.ajax({
                                        url: serverPath.systemPath + setter.sysLinkPath + "sysUser/del",
                                        type: "POST",
                                        dataType: 'json',
                                        data: t_date,
                                        success: function(data) {
                                            if (commons._filterRecord(data)) {
                                                layer.alert(data.msg);
                                                table.reload('userListTable', {
                                                    page: {curr: 1, limit: 10},
                                                });
                                                totalFilter.init('userListTable');
                                                commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                                            } else {
                                                layer.alert(data.msg);
                                            }
                                        }
                                    })
                                })
                            }
                            break;
                        case 'query':
                            common.tableConditionRender("userListTable","example",{where:{"orgId":selectOrgId}},false);
                            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                            break;
                        case 'clears':
                            common.tableConditionRender("userListTable","example",{where:{"orgId":selectOrgId}},true);
                            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                            break;
                        // case 'leader':
                        //     if (data.length === 0) {
                        //         layer.msg('请至少选择一行数据！');
                        //     } else {
                        //         var seleIds = [];
                        //         for (var i = 0; i < data.length; i++) {
                        //             seleIds.push(data[i].userId);
                        //         }
                        //         var t_date = {};
                        //         t_date.userId = seleIds.join(",");
                        //         layer.confirm('确定置为领导吗？', function() {
                        //             $.ajax({
                        //                 url: serverPath.systemPath + setter.sysLinkPath + "sysUser/setLeader",
                        //                 type: "POST",
                        //                 dataType: 'json',
                        //                 data: t_date,
                        //                 success: function(data) {
                        //                     if (commons._filterRecord(data)) {
                        //                         layer.alert(data.msg);
                        //                         table.reload('userListTable', {
                        //                             page: {curr: 1, limit: 10},
                        //                         });
                        //                         totalFilter.init('userListTable');
                        //                         commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                        //                     } else {
                        //                         layer.alert(data.msg);
                        //                     }
                        //                 }
                        //             })
                        //         })
                        //     }
                        //     break;
                        case 'batchupdate':
                            if (data.length === 0) {
                                layer.msg('请先选择一行数据！');
                            } else {
                                var seleIds = [];
                                for (var i = 0; i < data.length; i++) {
                                    seleIds.push(data[i].userId);
                                }
                                var ids = seleIds.join(",");
                                layer.open({
                                    type: 2,
                                    area: ['400px', '80%'],
                                    title: ['移动组织'],
                                    content: serverPath.systemPath +  setter.sysLinkPath + 'sysUser/view/move?ids=' + ids
                                });

                            }
                            break;
                        case 'impuser':
                            hideRMenu();
                            layer.open({
                                type: 1,
                                title: '导入用户',
                                shade: 0.3,
                                area: ['900px', '620px'],
                                content: $('.importUser-onfile'),
                                success:function(layor,index) {
                                    //关闭导入弹框
                                    $(".cancelData").click(function () {
                                        layer.close(index);
                                    })
                                }
                            }) ;
                            break;
                        case 'expuser':
                            var param_ = "";
                            $("form[lay-filter='example']").find(".filter-value").each(function() {
                                param_ += "&" + this.name + "=" + this.value;
                            });
                            window.open("/system/sysUser/outputExcelList?orgId="+selectOrgId+param_,"hidden_frame");
                            break;
                    }
                });

            var orgIdsels;

                //监听行工具事件
                table.on('tool(userListTable)', function(obj) {
                    var data = obj.data, //获得当前行数据
                        layEvent = obj.event; //获得 lay-event 对应的值
                    switch(layEvent){
                        case 'detail':
                            layer.open({
                                type: 2,
                                area: ['1000px', '620px'],
                                title: ['查看用户信息'],
                                content: serverPath.systemPath +setter.sysLinkPath + 'sysUser/view/view?userId='+data.userId
                            });
                            break;
                        case  'managementOfSub':
                            layer.open({
                                type: 2,
                                area: ['1000px', '620px'],
                                title: ['下属管理'],
                                content: serverPath.systemPath +  setter.sysLinkPath + 'sysUser/view/managementOfSub?userId=' + data.userId
                            });
                            break;
                        case 'setStatus':
                            layer.open({
                                type: 2,
                                area: ['666px', '430px'],
                                title: ['设置状态'],
                                content: serverPath.systemPath +  setter.sysLinkPath + 'sysUser/view/setStatus?userId=' + data.userId
                            });
                            break;
                        case 'resetPassword':
                            layer.open({
                                type: 2,
                                area: ['540px', '210px'],
                                title: ['重置密码'],
                                content: serverPath.systemPath +  setter.sysLinkPath + 'sysUser/view/ressetPass?userId=' + data.userId
                            });
                            break;
                        case 'del':
                            layer.confirm('确定删除当前数据吗？', function(index) {
                                layer.close(index);
                                $.ajax({
                                    url: serverPath.systemPath + setter.sysLinkPath + "sysUser/del",
                                    type: "POST",
                                    dataType: 'json',
                                    data: {userId:obj.data.userId},
                                    success: function(data) {
                                        if (commons._filterRecord(data)) {
                                            layer.alert(data.msg);
                                            table.reload('userListTable', {
                                                page: {curr: 1}
                                            });
                                            totalFilter.init('userListTable');
                                            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                                        } else {
                                            layer.alert(data.msg);
                                        }
                                    }
                                })
                            });
                            break;
                            case 'delLeader':
                            layer.confirm('确定当前用户取消领导吗？', function(index) {
                                layer.close(index);
                                $.ajax({
                                    url: serverPath.systemPath + setter.sysLinkPath + "sysUser/delLeader",
                                    type: "POST",
                                    dataType: 'json',
                                    data: {userId:obj.data.userId},
                                    success: function(data) {
                                        if (commons._filterRecord(data)) {
                                            layer.alert(data.msg);
                                            table.reload('userListTable', {
                                                page: {curr: 1}
                                            });
                                            totalFilter.init('userListTable');
                                            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                                        } else {
                                            layer.alert(data.msg);
                                        }
                                    }
                                })
                            });
                            break;
                        case 'edit':
                            layer.open({
                                type: 2,
                                area: ['1000px', '620px'],
                                title: ['修改用户信息'],
                                content: serverPath.systemPath +  setter.sysLinkPath +  'sysUser/view/addEdit?userId='+data.userId+'&selectOrgId='+selectOrgId
                            });
                            break;
                        case 'setOffline':
                            var currentElement=$(this);
                            layer.confirm('确定将此用户置为离线吗？', function(index) {
                                $.ajax({
                                    url: serverPath.systemPath + setter.sysLinkPath + "sysUser/setOffline",
                                    type: "post",
                                    dataType: 'json',
                                    data: {userId: obj.data.userId},
                                    success: function (data) {
                                        if (commons._filterRecord(data)) {
                                            layer.alert(data.msg);
                                            currentElement.removeClass('layui-btn-danger');
                                            currentElement.addClass('layui-btn-disabled').attr('disabled',true);
                                            // currentElement.addClass('ccpui-btn-disabled').attr('disabled',true);
                                        } else {
                                            layer.alert(data.msg);
                                        }
                                    },
                                });
                            });
                            break;
                        case 'editUserOrg':
                            var userOrgIndex = layer.open({
                                type: 1,
                                title: '选择用户所属组织',
                                shadeClose: false,
                                shade: 0.001,
                                maxmin: false, //开启最大化最小化按钮
                                area: ['400px', '584px'],
                                content: $('[name="configOrgDiv"]'),
                                success:function(layor,index) {
                                    userOrgZtree();
                                }
                            });

                            //展开
                            $(".orgSelectBtn .zTree-triangle-d").click(function() {
                                $.fn.zTree.getZTreeObj("configOrgData").expandAll(true);
                            });
                            //收起
                            $(".orgSelectBtn .zTree-triangle-r").click(function() {
                                $.fn.zTree.getZTreeObj("configOrgData").expandAll(false);
                            });
                            //刷新
                            $(".orgSelectBtn .zTree-refresh").click(function() {
                                userOrgZtree();
                            });

                            $('[name=configOrgDiv] .saveOrg').unbind("click");
                            $('[name=configOrgDiv] .saveOrg').bind('click',function () {
                                if(orgIdsels){
                                    //查询是否跨租户
                                    $.ajax({
                                        url: serverPath.systemPath + setter.sysLinkPath + "sysUser/searchIsStrideTenant",
                                        type: "post",
                                        dataType: 'json',
                                        data:{
                                            userId:data.userId,
                                            oldOrgId:data.orgId,
                                            orgId:orgIdsels
                                        },
                                        success: function(result) {
                                            if (commons._filterRecord(result)) {
                                                if(result.data){
                                                    //没有跨租户
                                                    layer.confirm('是否保留用户原来的角色？',{
                                                        btn: ["保留", "取消", "不保留"],
                                                        btn1: function (index1, layero) {
                                                            $.ajax({
                                                                url: serverPath.systemPath + setter.sysLinkPath + "sysUser/changeOrg",
                                                                type: "post",
                                                                dataType: 'json',
                                                                data:{
                                                                    userId:data.userId,
                                                                    orgId:orgIdsels,
                                                                    isKeep:1
                                                                },
                                                                success: function(data) {
                                                                    if (commons._filterRecord(data)) {
                                                                        layer.alert(data.msg, function (index) {
                                                                            layer.close(index);
                                                                            layer.close(userOrgIndex);
                                                                            table.reload('userListTable', {
                                                                                where:{"orgId":selectOrgId},
                                                                                page: {curr: 1, limit: 10}
                                                                            });
                                                                            totalFilter.init('userListTable');
                                                                            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                                                                        });
                                                                    } else {
                                                                        layer.alert(data.msg);
                                                                    }
                                                                },
                                                                error: function(XMLHttpRequest, textStatus, errorThrown) {
                                                                    layer.alert("保存失败！" + XMLHttpRequest.status);
                                                                },
                                                            })
                                                        },
                                                        btn3: function (index1, layero) {
                                                            $.ajax({
                                                                url: serverPath.systemPath + setter.sysLinkPath + "sysUser/changeOrg",
                                                                type: "post",
                                                                dataType: 'json',
                                                                data:{
                                                                    userId:data.userId,
                                                                    orgId:orgIdsels,
                                                                    isKeep:0
                                                                },
                                                                success: function(data) {
                                                                    if (commons._filterRecord(data)) {
                                                                        layer.alert(data.msg, function (index) {
                                                                            layer.close(index);
                                                                            layer.close(userOrgIndex);
                                                                            table.reload('userListTable', {
                                                                                where:{"orgId":selectOrgId},
                                                                                page: {curr: 1, limit: 10}
                                                                            });
                                                                            totalFilter.init('userListTable');
                                                                            commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                                                                        });
                                                                    } else {
                                                                        layer.alert(data.msg);
                                                                    }
                                                                },
                                                                error: function(XMLHttpRequest, textStatus, errorThrown) {
                                                                    layer.alert("保存失败！" + XMLHttpRequest.status);
                                                                },
                                                            })
                                                        }
                                                    });
                                                }else{
                                                    //跨租户
                                                    layer.confirm('租户变更，角色不能保留，是否要移动该人员？', function() {
                                                        $.ajax({
                                                            url: serverPath.systemPath + setter.sysLinkPath + "sysUser/changeOrg",
                                                            type: "post",
                                                            dataType: 'json',
                                                            data:{
                                                                userId:data.userId,
                                                                orgId:orgIdsels,
                                                                isKeep:0
                                                            },
                                                            success: function(data) {
                                                                if (commons._filterRecord(data)) {
                                                                    layer.alert(data.msg, function (index) {
                                                                        layer.close(index);
                                                                        layer.close(userOrgIndex);
                                                                        table.reload('userListTable', {
                                                                            where:{"orgId":selectOrgId},
                                                                            page: {curr: 1, limit: 10}
                                                                        });
                                                                        totalFilter.init('userListTable');
                                                                        commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                                                                    });
                                                                } else {
                                                                    layer.alert(data.msg);
                                                                }
                                                            },
                                                            error: function(XMLHttpRequest, textStatus, errorThrown) {
                                                                layer.alert("保存失败！" + XMLHttpRequest.status);
                                                            },
                                                        })
                                                    })
                                                }
                                            } else {
                                                layer.alert(data.msg);
                                            }
                                        },
                                        error: function(XMLHttpRequest, textStatus, errorThrown) {
                                            layer.alert("查询失败！" + XMLHttpRequest.status);
                                        },
                                    });

                                }else{
                                    layer.alert("未选择组织!");
                                    return false;
                                }
                            })
                            $('[name=configOrgDiv] .cancelOrg').unbind("click");
                            $('[name=configOrgDiv] .cancelOrg').bind('click',function () {
                                layer.close(userOrgIndex);
                            });
                            break;
                    }
                });

            function onClickUserData(event, treeId, treeNode, clickFlag) {
                orgIdsels = treeNode.orgId;
            }

            function userOrgZtree(){
                $.ajax({
                    url: serverPath.systemPath + setter.sysLinkPath + "sysOrg/list",
                    type: "get",
                    contentType: 'application/json',
                    dataType: 'json',
                    success: function(data) {
                        var zNodes = data.data;
                        var setting = {
                            view:{
                                nameIsHTML: true
                            },
                            data: {
                                key: {
                                        title: "orgName"
                                    },
                                simpleData: {
                                    enable: true,
                                    idKey:"orgId",
                                    pIdKey:"orgSupId"
                                }
                            },
                            callback: {
                                onClick: onClickUserData
                            }
                        };
                        $.fn.zTree.init($('#configOrgData'), setting, zNodes);
                        component.fuzzySearch('configOrgData','.orgZtreeValues',null,true); //初始化模糊搜索方法
                    },
                    error: function(XMLHttpRequest, textStatus, errorThrown) {
                        layer.alert("暂无数据，请稍后操作！" + XMLHttpRequest.status);
                    },
                })
            }

            //监听单元格编辑
            table.on('edit(userListTable)', function(obj){
                $.ajax({
                    url: serverPath.systemPath + setter.sysLinkPath + "sysUser/updateSortNumber",
                    type: "post",
                    dataType: 'json',
                    data: {userId: obj.data.userId,sortNumber:obj.value},
                    success: function (data) {
                        if (commons._filterRecord(data)) {
                            layer.alert(data.msg);

                            table.reload('userListTable', {
                                page: {curr: 1, limit: 10},
                            });

                        } else {
                            layer.alert(data.msg);
                        }
                    },
                });
            });

                //监听删除
                window.Initialization = function () {
                    commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                };
                /*刷新时间控件*/
                commons.reflashDate({startName:'.start_time',endName:'.end_time'});
                common.tableSort("userListTable",{show:window.Initialization});
            });
    </script>
</body>
</html>
<link rel="stylesheet" href="${ctx}/css/font/iconfontie.css" media="all"/>
<link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>


